<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>添加员工信息</legend>
</fieldset>

<form class="layui-form" action="" id="Emp">
    <div class="layui-form-item">
        <label class="layui-form-label">真实姓名</label>
        <div class="layui-input-block">
            <input type="text" id="e_truename" name="e_truename" lay-verify="title" autocomplete="off" placeholder="真实姓名" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登录名称</label>
        <div class="layui-input-block">
            <input type="text" id="e_loginname" name="e_loginname" lay-verify="title" autocomplete="off" placeholder="登录名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">员工密码</label>
        <div class="layui-input-inline">
            <input type="password" id="e_psw" name="e_psw" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所在部门</label>
        <div class="layui-input-block">
            <select id="p_id" name="p_id" class="layui-form-select" lay-filter="EmpFilter">
                <!--                <option value=""></option>-->
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">员工性别</label>
        <div class="layui-input-block" id="e_sex">
            <input type="radio" name="e_sex" value="男" title="男" checked="">
            <input type="radio" name="e_sex" value="女" title="女">
            <input type="radio" name="e_sex" value="禁" title="禁用" disabled="">
        </div>
    </div>
    <div class="layui-upload">
          <button type="button" class="layui-btn" id="test1">上传图片</button>
          <div class="layui-upload-list">
            <input type="file" name="file" id="e_img">
          </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">员工备注</label>
        <div class="layui-input-block">
            <textarea id="e_remark" class="e_remark" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">员工类别</label>
            <div class="layui-input-inline">
                <select id ="e_flag" name="e_flag" lay-verify="required" lay-search="">
                    <option value="0">普工</option>
                    <option value="1">主管</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">权限级别</label>
            <div class="layui-input-inline">
                <select id ="e_admin" name="e_admin" lay-verify="required" lay-search="">
                    <option value="0">普通操作者</option>
                    <option value="1">部门主管</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>



<script src="../../layui/layui.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    function getValue() {
        var e_truename = document.getElementById("e_truename").value;
        var e_loginname = document.getElementById("e_loginname").value;
        var e_psw = document.getElementById("e_psw").value;
        var p_id = document.getElementById("p_id").value;
        var e_sex = null;
        var obj = document.getElementsByName("e_sex")
        for (var i = 0; i < obj.length; i++) { //遍历Radio
            if (obj[i].checked) {
                e_sex = obj[i].value;
            }
        }

        var e_img = document.getElementById("e_img").value;
        var e_remark = document.getElementById("e_remark").value;
        var e_flag = document.getElementById("e_flag").value;
        var e_admin = document.getElementById("e_admin").value;
        var data = {
            "e_truename": e_truename,
            "e_loginname": e_loginname,
            "e_psw": e_psw,
            "p_id": p_id,
            "e_sex": e_sex,
            "e_img": e_img,
            "e_remark": e_remark,
            "e_flag": e_flag,
            "e_admin": e_admin
        }
        alert(data);
        return data
    }


</script>
<script>
    layui.use(['table','form','jquery','layer'], function() {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;
        //页面加载时向下拉选框中加载数据
        $(document).ready(function() {
            axios.post('/firstWeb/selectP_name').then(function (response) {
                var role = document.getElementById("p_id");
                var data = response.data;
                var value = Object.keys(data);
                var label = Object.values(data);
                for(var i = 0; i < data.length; i++) {
                    var value = Object.keys(data);
                    var label = Object.values(data);
                    var option = document.createElement("option");  // 创建添加option属性
                    option.setAttribute("value", value[i]); 	    // 给option的value添加值
                    option.innerText = label[i];    			    // 打印option对应的纯文本
                    role.appendChild(option);  					    // 给select添加option子标签
                }
                form.render("select");
            }).catch(function (error) {
                console.log(error);
            });
        });

    });

</script>
<script>
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;

    });
</script>
<script>
    layui.use('upload', function(){
        var $ = layui.jquery
            ,upload = layui.upload;

        //绑定原始文件域
        upload.render({
            elem: '#e_img'
            ,url: '/firstWeb/upload'
            ,done: function(res){
                console.log(res)
            }
        });
    });
</script>

</body>
</html>